<?php

namespace BasicAdmin\Models;

use mszl\api\utils\DbMySQL;

class BaseModel extends DbMySQL
{
    const STATE_NORMAL = 0;
    const STATE_DEL = 8;

    public static function normalSelect($where = [], $fields = '*')
    {
        if (empty($where['state'])) $where['state'] = static::STATE_NORMAL;
        return self::select($fields, $where);
    }

    public static function normalSelectMap($where = [], $fields = '*', $primary = 'id'): array
    {
        $list = self::normalSelect($where, $fields);
        return $list ? array_column($list, null, $primary) : [];
    }

    public static function insertGetId($data): string
    {
        self::insert($data);
        return self::id();
    }
}
